﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.DAL.Providers
{
    public class OrderProvider : ProviderBase<Order,OrderSearchCriteria>
    {
        public override void Insert(Order item)
        {
            throw new NotImplementedException();
        }

        public int InsertOrder(Order order)
        {
            Context.Orders.AddObject(order);
            Context.SaveChanges();
            return order.ID;
        }

        public override void Update(Order updatedItem)
        {
            throw new NotImplementedException();
        }

        public override void Delete(int id)
        {
        }

        public override Order GetByID(int id)
        {
            return (from o in Context.Orders
                    where (o.ID == id)
                    select o).FirstOrDefault();
        }

        public override List<Order> Search(OrderSearchCriteria SearchCriteria)
        {
            var Quary = (from o in Context.Orders
                         where (((o.ID == SearchCriteria.ID)|| (SearchCriteria.ID == 0)) &&
                         ((SearchCriteria.date == o.Date) || (SearchCriteria.date == null)) &&
                         ((SearchCriteria.type == o.Type) || (SearchCriteria.type == 0)) &&
                         ((SearchCriteria.CustomerID == o.CustomerID)||(SearchCriteria.CustomerID ==0)))
                         select o).ToList();
            return Quary;
        }
    }
}
